package com.htg.dialog;

import android.app.AlertDialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;



public class DialogDonotKnowPosition {

    private Context cxt;
    private AlertDialog alertDialog;

    public DialogDonotKnowPosition(Context cxt) {
        this.cxt = cxt;
    }

    public void show(OnDialogDonnotKnowPositionOperationListener onDialogDonnotKnowPositionOperationListener) {

        if (alertDialog == null) {
            AlertDialog.Builder builder = new AlertDialog.Builder(cxt);
            alertDialog = builder.create();
        } else {
            if (alertDialog.isShowing()) {
                return;
            }
        }
        alertDialog.show();
        View view = LayoutInflater.from(cxt).inflate(R.layout.dialog_donot_know_position, null);
        Window window = alertDialog.getWindow();
        window.setBackgroundDrawableResource(R.drawable.shape_alpha);
        WindowManager.LayoutParams params = window.getAttributes();
        int width = cxt.getResources().getDimensionPixelSize(R.dimen.dp_260);

        params.width = width;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(params);
        //window.setLayout(WindowManager.LayoutParams.MATCH_PARENT,WindowManager.LayoutParams.WRAP_CONTENT);
        window.setContentView(view);

        TextView tvChoose = view.findViewById(R.id.tv_dialog_donotknowposition_choose);
        TextView tvLocate = view.findViewById(R.id.tv_dialog_donotknowposition_locate);
        LinearLayout llDonothint = view.findViewById(R.id.ll_dialog_donotknowposition_donothint);
        CheckBox cbDonothint = view.findViewById(R.id.cb_dialog_donotknowposition_donothint);
        RelativeLayout rlClose = view.findViewById(R.id.rl_dialog_donotknowposition_close);

        tvChoose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                if (onDialogDonnotKnowPositionOperationListener!=null){
                    onDialogDonnotKnowPositionOperationListener.onDialogDonnotKnowPositionChoose(cbDonothint.isChecked());
                }
            }
        });
        tvLocate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                if (onDialogDonnotKnowPositionOperationListener!=null){
                    onDialogDonnotKnowPositionOperationListener.onDialogDonnotKnowPositionLocate(cbDonothint.isChecked());
                }
            }
        });
        rlClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                if (onDialogDonnotKnowPositionOperationListener!=null){
                    onDialogDonnotKnowPositionOperationListener.onDialogDonnotKnowPositionClose(cbDonothint.isChecked());
                }
            }
        });
    }

    public void dismiss() {
        if (alertDialog != null)
            alertDialog.dismiss();
    }


    public interface OnDialogDonnotKnowPositionOperationListener {
        void onDialogDonnotKnowPositionClose(boolean donothint);

        void onDialogDonnotKnowPositionChoose(boolean donothint);

        void onDialogDonnotKnowPositionLocate(boolean donothint);
    }


}
